package 作业.卖票案例1;

public class MyRunnable implements Runnable {
    private Object o = new Object();
    private int ticket = 100;
    @Override
    public void run() {
        while (true){
            synchronized (o) {
                if (ticket > 0) {
                    System.out.println(Thread.currentThread().getName() + "正在卖第" + ticket + "张票");
                    ticket--;
                } else {
                    break;
                }
            }
        }
    }
}
